//
// Created by lenovo on 2024/1/13.
//

#include "./Triangle.h"
#include <cmath>


namespace Functions{

    class Sin: public iFunction{
    public :
        Sin(){
            this->_argc = 1 ;
        }
        double calc(std::vector<double> _argv) override{
            if (_argv.empty()){
                throw std::logic_error("EMPTY arg for Funcs Sin , But 1 is Required");
            }
            if (_argv.size() > 1){
                throw std::logic_error("Too MUCH args for Funcs Sin ,Only 1 is Required");
            }
            return std::sin(_argv[0]);
        }
    };
    Sin sin ;

    class Cos: public iFunction{
    public :
        Cos(){
            this->_argc = 1 ;
        }
        double calc(std::vector<double> _argv) override{
            if (_argv.empty()){
                throw std::logic_error("EMPTY arg for Funcs Cos , But 1 is Required");
            }
            if (_argv.size() > 1){
                throw std::logic_error("Too MUCH args for Funcs Cos ,Only 1 is Required");
            }
            return std::cos(_argv[0]);
        }
    };
    Cos cos ;

    class Tan: public iFunction{
    public :
        Tan(){
            this->_argc = 1 ;
        }
        double calc(std::vector<double> _argv) override{
            if (_argv.empty()){
                throw std::logic_error("EMPTY arg for Funcs Tan , But 1 is Required");
            }
            if (_argv.size() > 1){
                throw std::logic_error("Too MUCH args for Funcs Tan ,Only 1 is Required");
            }
            return std::tan(_argv[0]);
        }
    };
    Tan tan ;


    std::map<
            std::string ,
            iFunction*
    >
    TriangleFunc = {
            {"sin",&sin},
            {"cos",&cos},
            {"tan",&tan}
    };
}


